# 完成测试用例
# 通过 调用 接口类中方法（传递测试数据）完成 断言和关联
# 导包
import logging
from api.login import LoginAPI
import config
import pytest


# 构造测试数据
def build_data():
    return [({"mobile": "13800000002", "password": "123456"}, 200, True, 10000, "成功"),
            ({"mobile": "", "password": "123456"}, 200, False, 20001, "错误"),
            ({"mobile": "13800000002", "password": ""}, 200, False, 20001, "错误")]


# 创建测试类
class TestLoginAPI:
    # 前置处理
    def setup(self):
        # 实例化接口类
        self.login_api = LoginAPI()

    # 登录
    @pytest.mark.parametrize("login_data, status_code, success, code, message", build_data())
    def test_login(self, login_data, status_code, success, code, message):
        response = self.login_api.login(login_data)
        # print(response.json())
        logging.debug(response.json())
        # 断言响应状态码为200
        assert response.status_code == status_code
        # 断言json返回数据success值
        assert response.json().get("success") is success
        # 断言json返回数据中code值
        assert response.json().get("code") == code
        # 断言json返回数据中message包含指定字符串
        assert message in response.json().get("message")

